package com.approval.approvalapp.index.dbsx.wzsp.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.WzspXqBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/5/7.
 */

public class WzxqRvAdapter extends RecyclerView.Adapter<WzxqRvAdapter.Holder> {

    Context context;
    List<WzspXqBean.ListBeanX> listBeanXES;

    public void setListBeanXES(List<WzspXqBean.ListBeanX> listBeanXES) {
        this.listBeanXES = listBeanXES;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_wzxq, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        holder.tv1.setText("物资名称");
        holder.tv2.setText("数量");
        if (position == 0){
            holder.hll.setVisibility(View.VISIBLE);
        }else {
            holder.hll.setVisibility(View.GONE);
        }
        holder.rv.setLayoutManager(new LinearLayoutManager(context));
        ItemAdapter itemAdapter = new ItemAdapter();
        itemAdapter.setBeanList(listBeanXES.get(position).getList());
        holder.rv.setAdapter(itemAdapter);
    }

    @Override
    public int getItemCount() {
        if (listBeanXES == null) {
            return 0;
        } else {
            return listBeanXES.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv2)
        TextView tv2;
        @Bind(R.id.rv)
        RecyclerView rv;
        @Bind(R.id.hll)
        LinearLayout hll;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.Holder> {
        Context context;
        List<WzspXqBean.ListBeanX.ListBean> beanList;


        public void setBeanList(List<WzspXqBean.ListBeanX.ListBean> beanList) {
            this.beanList = beanList;
            notifyDataSetChanged();
        }

        @Override
        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
            context = parent.getContext();
            View view = LayoutInflater.from(context).inflate(
                    R.layout.item_item_wzxq, parent, false
            );
            Holder holder = new Holder(view);
            return holder;
        }

        @Override
        public void onBindViewHolder(Holder holder, int position) {
            holder.tv1.setText(beanList.get(position).getTitle());
            holder.tv2.setText(beanList.get(position).getCount() + "");
        }

        @Override
        public int getItemCount() {
            if (beanList == null) {
                return 0;
            } else {
                return beanList.size();
            }
        }

        class Holder extends RecyclerView.ViewHolder {
            @Bind(R.id.tv1)
            TextView tv1;
            @Bind(R.id.tv2)
            TextView tv2;
            public Holder(View itemView) {
                super(itemView);
                ButterKnife.bind(this,itemView);
            }
        }
    }

}
